﻿// 1015 德才论.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

struct stu {
	int no;
	int de;
	int cai;
};

int low, high;

//1：均高于H
//2：德高于H，才低于H
//3：德才均低于H，但德》=才
//4：其它德才>l
//0：表示不被录取
int judge(int de, int cai) {
	if (de < low || cai < low) {
		return 0;
	}
	//1
	if (de >= high && cai >= high) {
		return 1;
	}
	//2        
	if (de >= high && cai < low) {
		return 2;
	}
	//3
	if (de >= cai) {
		return 3;
	}
	return 4;
}

bool cmp(stu a, stu b) {
	return a.de + a.cai == b.de + b.cai ? a.de == b.de ? a.no<b.no : a.de>b.de : a.de + a.cai > b.de + b.cai;
}

int main()
{
	int n, l, h;//n总人数，l及格线，h优先录取线
	int m = 0;//过线人数
	cin >> n >> l >> h;
	low = l;
	high = h;
	int thisno, thisde, thiscai;

	vector<stu> v1, v2, v3, v4;
	for (int i = 0; i < n; i++) {
		stu s;
		cin >> thisno >> thisde >> thiscai;
		s.no = thisno;
		s.de = thisde;
		s.cai = thiscai;
		int tmp = judge(s.de, s.cai);
		if (tmp) {
			m++;
		}
		switch (tmp) {
		case 1:
			v1.push_back(s);
			break;
		case 2:
			v2.push_back(s);
			break;
		case 3:
			v3.push_back(s);
			break;
		case 4:
			v4.push_back(s);
			break;
		}
	}
	sort(v1.begin(), v1.end(), cmp);
	sort(v2.begin(), v2.end(), cmp);
	sort(v3.begin(), v3.end(), cmp);
	sort(v4.begin(), v4.end(), cmp);
	//按类别输出    
	cout << m << endl;
	for (auto it = v1.begin(); it != v1.end(); it++)
		cout << it->no << " " << it->de << " " << it->cai << endl;
	for (auto it = v2.begin(); it != v2.end(); it++)
		cout << it->no << " " << it->de << " " << it->cai << endl;
	for (auto it = v3.begin(); it != v3.end(); it++)
		cout << it->no << " " << it->de << " " << it->cai << endl;
	for (auto it = v4.begin(); it != v4.end(); it++)
		cout << it->no << " " << it->de << " " << it->cai << endl;

	return 0;
}
